<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="./css/aui.css" />
    <link rel="stylesheet" type="text/css" href="./css/common.css" />
    <style type="text/css">
        /*.jb2{
        background: #FF512F;
        background: -webkit-linear-gradient(to left, #ce5344 25%, #d5372b 75%);
        background: linear-gradient(to left, #ce5344 25%, #d5372b 75%);
    }*/
        #jb,
        .jb {
            background: white;
        }

        .aui-searchbar-input {
            background-color: #F3F3F3
        }

        .aui-btn img {
            width: 1rem;
            height: 1rem;
        }

        .aui-bar-nav .aui-title {
            min-height: 1rem;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav jb" id="header">
        <div class="h h1">
            <!-- <a class="aui-pull-left aui-btn">
                <span class="aui-iconfont aui-icon-calendar" onclick="openPublic(this)"></span>
            </a> -->
            <a class="aui-pull-left aui-btn" onclick="zhichi()">
                <img src="image/newImg/kf@3x.png" alt="" class="aui_img">
                <!--<img src="image/xiaoxitubiao.png" alt="" class="aui_img">-->
            </a>
            <div class="aui-title" style="left:1.5rem; right: 1.5rem;" onclick="openWin('search_win')">
                <div class="aui-searchbar" id="search" style="background: transparent;">
                    <div class="aui-searchbar-input aui-border-radius jb2" style="border-radius: 5rem;height:1.4rem;line-height:1.4rem;">
                        <i class="aui-iconfont aui-icon-search" style="font-size: .7rem;color:#999999 !important"></i>
                        <input type="search" placeholder="请输入搜索的宝贝名称" disabled="" style="color:#999999 !important">
                        <div class="aui-searchbar-clear-btn" style="color:#333333;">
                            <i class="aui-iconfont aui-icon-close" style="color:#333333;"></i>
                        </div>
                    </div>
                </div>
            </div>
            <a class="aui-pull-right aui-btn" onclick="show_tb_cart2()">
                <img src="image/newImg/car@3x.png" alt="" class="aui_img">
            </a>
        </div>
        <div class="h h2 hide">
            <div class="aui-searchbar" style="background: transparent;" onclick="openWin('search_win')">
                <div class="aui-searchbar-input aui-border-radius jb2" style="border-radius: 5rem;margin:0 1.5rem;">
                    <i class="aui-iconfont aui-icon-search" style="font-size: .7rem;color:#999999 !important"></i>
                    <input type="search" placeholder="请输入搜索的宝贝名称" disabled="" style="color:#999999 !important">
                    <div class="aui-searchbar-clear-btn" style="color:red;">
                        <i class="aui-iconfont aui-icon-close" style="color:red;"></i>
                    </div>
                </div>
            </div>
            <!-- <div class="aui-title"></div>
            <a class="aui-pull-right aui-btn" onclick="openWin('search_win')">
                <span class="aui-iconfont aui-icon-search"></span>
            </a> -->
        </div>
        <div class="h h3 hide">
            <div class="aui-title" style="left:2.25rem; right: 2rem;color:#333333;"></div>
            <a class="aui-pull-right aui-btn" onclick="openWin('search_win')" style="padding:0 0.5rem">
                <i class="aui-iconfont aui-icon-search" style="font-size: 0.8rem;color:#333 !important"></i>
            </a>
        </div>
    </header>
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript" src="./script/zepto.min.js"></script>
<script type="text/javascript" src="./script/common.js"></script>
<script type="text/javascript" src="./script/jpush/index.js"></script>
<script type="text/javascript">
    var keyBackCount = 0,
        headerH, aliBC = null,
        copy = 1;
    apiready = function () {

        var phoneType = 0,deviceId = api.deviceId,urlTransform ='';
        var iAd = api.require('iAd');
        var phoneInfoMore = api.require('phoneInfoMore');
        var hardwareInfo = api.require('hardwareInfo');

        if(api.systemType == 'ios'){
          phoneType= 1
          var iAd = iAd.getIDFA({
          lowerCase:false
          },function(ret){
             if (ret.status) {
               var idfa = ret.IDFA,mac=''
               hardwareInfo.getIpMacAddrList(function(ret,err)
               {
                   if(err){
                     console.log(err);
                   }else{
                     mac = ret[0].macAddr
                     urlTransform = "http://tongji.molbait.cn/statistics/deviceInfo?os="+phoneType+"&idfa="+idfa+"&deviceId="+deviceId+"&mac="+mac
                   }
               });
             }
          });
        }else{
          // if(api.systemType == 'android')
          phoneInfoMore.getBaseInfo(function(ret, err) {
              console.log(JSON.stringify(ret));
              if(ret){
                  urlTransform = "http://tongji.molbait.cn/statistics/deviceInfo?os="+phoneType+"&deviceId="+deviceId+"&mac="+ret.ipMac+"&imei="+ret.imei+"&androidId="+ret.androidId
              }
          });
        }

        setTimeout(function(){
          console.log(urlTransform)
          _Ajax(urlTransform, 'get', {}, 'json', function (ret) {
              console.log(JSON.stringify(ret))
          });
        },2000)



        api.parseTapmode();
        var header = $api.byId('header');
        headerH = $api.fixStatusBar(header);
        aliBC = api.require("aliBC");
        init_baichuan();
        index_group();
        get_nav();
        NVTabBar_open();

        listen_copy();
        //监听应用回到前台
        api.addEventListener({
            name: 'resume'
        }, function (ret, err) {
            if (api.systemType == 'ios') {
                listen_copy();
            }
        });
        //极光推送，初始化
        var ajpush = api.require('ajpush');
        ajpush.init(function (ret) {
            if (ret && ret.status) {
                //success
            }
        });
        //清除通知
        ajpush.clearNotification({
            id: -1
        });

        /**
         * 监听安卓物理返回键
         * 按两次退出
         */
        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            if (!keyBackCount) {
                _toast('再按一次退出');
                keyBackCount++;
            } else {
                api.closeWidget({
                    id: api.appId,
                    silent: true,
                    animation: {
                        type: 'none'
                    }
                });
            }
        });
        //云修复
        api.addEventListener({
            name: 'smartupdatefinish'
        }, function (ret, err) {
            //_toast('更新数据完成');
            api.rebootApp();
        });
        //监听站内复制
        _AddEventListener('app_copy', function (ret) {
            copy = 0;
        });

        _Ajax('http://v2.zhengouduo.com/app/ad/bulletin', 'get', {}, 'json', function (ret) {
            if (ret.code === 1) {
                var data = ret.data.bulletin_list
                // 是否自动弹出 1 弹出 0 不弹出
                // 是否维img 如果是 则 弹出
                if (data.is_auto_popup === 1 && data[0].type === 'IMG') {
                    // 首页弹窗
                    api.openFrame({
                        name: 'dialog',
                        url: './html/dialog.html',
                        rect: {
                            x: 0,
                            y: 0,
                            w: api.winWidth,
                            h: api.winHeight,
                        },
                        bgColor: 'rgba(0,0,0,0.6)',
                        bounces: false,
                        pageParam: {
                            imgSrc: data[0].content
                        }
                    });
                }
            }
        });
    };

    function show_tb_cart() {
        api.openWin({
            name: 'messageList',
            url: './html/messageList.html',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: 'auto'
            }
        });
    }

    function get_nav() {
        api.openFrame({
            name: 'nav',
            url: 'widget://html/nav.html',
            bounces: false,
            rect: { // 推荐使用Margin布局，用于适配屏幕的动态变化
                marginTop: headerH, // main页面距离win顶部的高度
                w: 'auto', // main页面的宽度 自适应屏幕宽度
                h: 35
            }
        });
    }

    //frame 预加载
    function index_group() {
        api.openFrameGroup({
            name: 'index_group',
            //background: '#FF512F',
            scrollEnabled: false,
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: 'auto',
                marginBottom: 52
            },
            index: 0,
            preload: 1,
            frames: [{
                    name: 'index_frm',
                    url: 'widget://html/index_frm.html',
                    useWKWebView: true
                },
                {
                    name: 'super_class_frm',
                    url: 'widget://html/super_class_frm.html',
                    useWKWebView: true
                },
                {
                    name: 'search_tool_frm',
                    url: 'widget://html/search_tool_frm.html',
                    useWKWebView: true
                },
                {
                    name: 'source_list_frm',
                    url: 'widget://html/source_list_frm.html',
                    useWKWebView: true
                },
                {
                    name: 'my_frm',
                    url: 'widget://html/my_frm.html',
                    useWKWebView: true
                }
            ]
        }, function (ret, err) {
            if (ret.index == 0) {
                api.setFrameGroupAttr({
                    name: 'index_group',
                    rect: {
                        x: 0,
                        y: headerH + 35,
                        w: 'auto',
                        h: 'auto'
                    }
                });
            }

        });
    }
    //底部菜单
    function NVTabBar_open() {
        var NVTabBar = api.require('NVTabBar');
        NVTabBar.open({
            styles: {
                bg: '#fff',
                //bg:"widget://image/NVTabBar/tabbar_bg.png",
                h: 53,
                dividingLine: {
                    width: 0.5,
                    color: '#ddd'
                },
                badge: {
                    bgColor: '#ff0',
                    numColor: '#fff',
                    size: 6.0,
                    centerX: 40,
                    centerY: 6
                }
            },
            items: [{
                w: api.winWidth / 5.0,
                bg: {
                    marginB: -3,
                    image: 'rgba(0,0,0,0)'
                },
                iconRect: {
                    w: 25.0,
                    h: 25.0,
                },
                icon: {
                    normal: 'widget://image/footer/syoff.png',
                    highlight: 'widget://iimage/footer/syoff.png',
                    selected: 'widget://image/footer/syon.png'
                },
                title: {
                    text: '首页',
                    size: 12.0,
                    normal: '#92939c',
                    selected: '#FE417A',
                    marginB: 6.0
                }
            }, {
                w: api.winWidth / 5.0,
                bg: {
                    marginB: -3,
                    image: 'rgba(0,0,0,0)'
                },
                iconRect: {
                    w: 25.0,
                    h: 25.0,
                },
                icon: {
                    normal: 'widget://image/footer/floff.png',
                    highlight: 'widget://image/footer/floff.png',
                    selected: 'widget://image/footer/flon.png',
                },
                title: {
                    text: '分类',
                    size: 12.0,
                    normal: '#92939c',
                    selected: '#FE417A',
                    marginB: 6.0
                }
            }, {
                w: api.winWidth / 5.0,
                bg: {
                    marginB: 5,
                    //image: 'widget://image/footer/3.png' //中间背景图
                },
                iconRect: {
                    w: 56,
                    h: 56,
                },
                icon: {
                    normal: 'widget://image/footer/sqoff.png',
                    highlight: 'widget://image/footer/sqoff.png',
                    selected: 'widget://image/footer/sqon.png'
                },
                title: {
                    text: '搜券',
                    size: 12,
                    normal: '#92939c',
                    selected: '#FE417A',
                    marginB: 6
                }
            }, {
                w: api.winWidth / 5.0,
                bg: {
                    marginB: -3,
                    image: 'rgba(0,0,0,0)'
                },
                iconRect: {
                    w: 25.0,
                    h: 25.0,
                },
                icon: {
                    normal: 'widget://image/footer/fxoff.png',
                    highlight: 'widget://image/footer/fxoff.png',
                    selected: 'widget://image/footer/fxon.png'
                },
                title: {
                    text: '发现',
                    size: 12.0,
                    normal: '#92939c',
                    selected: '#FE417A',
                    marginB: 6.0
                }
            }, {
                w: api.winWidth / 5.0,
                bg: {
                    marginB: -3,
                    image: 'rgba(0,0,0,0)'
                },
                iconRect: {
                    w: 25.0,
                    h: 25.0,
                },
                icon: {
                    normal: 'widget://image/footer/wdoff.png',
                    highlight: 'widget://image/footer/wdoff.png',
                    selected: 'widget://image/footer/wdon.png'
                },
                title: {
                    text: '我的',
                    size: 12.0,
                    normal: '#92939c',
                    selected: '#FE417A',
                    marginB: 6.0
                }
            }],
            selectedIndex: 0
        }, function (ret, err) {
            api.bringFrameToFront({
                from: 'listen_copy_frm'
            });
            if (ret) {
                if (ret.eventType == 'click') {
                    var head_text = ['珍购多', '分类', '搜券', '发现', '我的'];

                    //$api.text($api.dom('#header'),head_text[ret.index]);

                    if (ret.index == 0) {
                        $('.h').hide();
                        $('.h1').show();
                        api.setFrameGroupAttr({
                            name: 'index_group',
                            rect: {
                                x: 0,
                                y: headerH + 35,
                                w: 'auto',
                                h: 'auto'
                            }
                        });
                        api.setFrameAttr({
                            name: 'nav',
                            hidden: false
                        });
                    } else {
                        var h = 0;
                        // if (ret.index==1 || ret.index==3) {
                        //     $('.h').hide();
                        //     $('.h2').show();
                        //     $('.h2 .aui-title').text(head_text[ret.index])
                        //     h = headerH;
                        // }

                        if (ret.index == 1) {
                            $('.h').hide();
                            $('.h2').show();
                            $('.h2 .aui-title').text(head_text[ret.index])
                            h = headerH;
                        } else if (ret.index == 3) {
                            $('.h').hide();
                            $('.h3').show();
                            $('.h3 .aui-title').text(head_text[ret.index])
                            h = headerH;
                        }

                        api.setFrameAttr({
                            name: 'nav',
                            hidden: true
                        });
                        api.setFrameGroupAttr({
                            name: 'index_group',
                            rect: {
                                x: 0,
                                y: h,
                                w: 'auto',
                                h: 'auto'
                            }
                        });
                    }
                    api.setFrameGroupIndex({
                        name: 'index_group',
                        index: ret.index
                    });
                }
            }
        });
    }

    //百川初始化
    //初始化就退出,注意是配置文件，其它模块参数不能为空
    function init_baichuan() {
        //初始化阿里巴川
        aliBC.asyncInit({
            addLoginState: true //用于监听淘宝授权登录成功事件，若为false则无TBLoginEvent事件发出
        }, function (ret, err) {
            if (ret.status) {
                //alert(JSON.stringify(ret))
                //初始化成功后，根据需求设置全局参数
                // aliBC.setSyncForTaoke();
                // aliBC.setTaokeParams({
                //   pid:''
                // });
                // aliBC.setChannel({
                //   typeName:'1',
                //   channelName:'test'
                // });
            } else {
                //alert(JSON.stringify(err));
            }
        });
        /*
        //淘宝登录成功事件监听
        api.addEventListener({
            name: 'TBLoginEvent'
        }, function(ret, err) {
            if (ret) {
                //alert('TBLoginEvent--'+JSON.stringify(ret));
                //绑定
                _Ajax(window.APIServer.BindTb,'post',{values:ret.value},'json',function(ret){
                    if (ret.code!=1) {
                        _toast(ret.msg)
                        aliBC.logout(function(ret,err){});//清除授权
                    }
                })
            }
        });
        */
    }
    //打开购物车
    // function show_tb_cart() {
    //     aliBC.getUserInfo(function (ret, err) {
    //         if (ret.status) {
    //             _Ajax(window.APIServer.BindTb, 'post', {
    //                 values: ret
    //             }, 'json', function (ret) {
    //                 if (ret.code == 1) {
    //                     show_tb_cart2();
    //                 } else {
    //                     _toast(ret.msg)
    //                     aliBC.logout(function (ret, err) {}); //清除授权
    //                 }
    //             })
    //         } else {
    //             //登录
    //             aliBC.showLogin(function (ret, err) {
    //                 if (ret.status) {
    //                     _Ajax(window.APIServer.BindTb, 'post', {
    //                         values: ret
    //                     }, 'json', function (ret) {
    //                         if (ret.code == 1) {
    //                             show_tb_cart2();
    //                         } else {
    //                             _toast(ret.msg)
    //                             aliBC.logout(function (ret, err) {}); //清除授权
    //                         }
    //                     })
    //                 } else {
    //                     _toast('授权失败');
    //                 }
    //             });
    //         }
    //     });
    // }

    function show_tb_cart2() {
        aliBC.showMyCarts({
            pid: 'mm_119186568_180200053_52526800462'
        }, function (ret, err) {
            if (ret) {
                //alert(JSON.stringify(ret));
            } else {
                //alert(JSON.stringify(err));
            }
        });
    }

    function listen_copy() {
        var clipBoard = api.require('clipBoard');
        clipBoard.get(function (ret, err) {
            if (ret) {
                var value = ret.value;
                if (ret.type == 'string' && value != '') {
                    copy_dialog(value);
                    //clipBoard.set({value:''});
                    return false;
                }
            }
        });
        clipBoard.setListener(function (ret, err) {
            if (ret) {
                copy_dialog(ret.value);
            }
        });
    }

    function copy_dialog(value) {
        if (copy == 0) {
            copy = 1;
            return false;
        }
        api.openFrame({
            name: 'listen_copy_frm',
            url: 'widget://html/listen_copy_frm.html',
            bounces: false,
            rect: {
                x: 0,
                y: 0,
                w: api.winWidth,
                h: api.winHeight
            },
            pageParam: {
                text: value
            }
        });
    }
    // 监听滚动条 add by alison
    window.onscroll = function () {
        var h = $(window).scrollTop();
        //console.log(h)
        if (h >= (w - 300)) {
            $("#goTop").removeClass("hide");
        } else if (h == 0) {
            $("#goTop").addClass("hide");
        }

    }
    // 返回顶部
    function goTop() {
        $("body").scrollTop(0)
    }
    //积分商城
    function duiba(type) {
        _loading2();
        _Ajax(window.APIServer.Duiba, 'post', {
            values: {}
        }, 'json', function (ret) {
            _loading2_close();
            if (ret.code == 1) {
                if (type == 'sign') {
                    openWeb({
                        url: ret.data.sign_url,
                        title: '每日签到'
                    });
                } else {
                    openWeb({
                        url: ret.data.autologin_url,
                        title: '积分商城'
                    });
                }

            } else {
                _toast(ret.msg)
            }
        })
    }
</script>

</html>
